package com.uft.security.tam.utils;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedCredentialsNotFoundException;
import org.springframework.util.StringUtils;

public class AutoLoginFilter extends AbstractPreAuthenticatedProcessingFilter{
	public static String principalUserRequestHeader ="iv-user";
	public static String principalGroupRequestHeader ="iv-groups";
	
	@Override
	protected Object getPreAuthenticatedPrincipal(HttpServletRequest request) {
		// TODO Auto-generated method stub
		String user=request.getHeader(AutoLoginFilter.principalUserRequestHeader);
		if(StringUtils.hasLength(user)){
			return user;
		}else
			throw new PreAuthenticatedCredentialsNotFoundException(AutoLoginFilter.principalUserRequestHeader+" Header not found in request");
	}

	@Override
	protected Object getPreAuthenticatedCredentials(HttpServletRequest request) {
		// TODO Auto-generated method stub
		String user=request.getHeader(AutoLoginFilter.principalUserRequestHeader);
		if(StringUtils.hasLength(user)){
			return user;
		}else
			throw 
			new PreAuthenticatedCredentialsNotFoundException(AutoLoginFilter.principalUserRequestHeader+" Header not found in request");
	}

}
